<?php

declare(strict_types=1);

namespace App\Controller;

use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\AutoController;

#[AutoController]
class FileController
{
    public function upload_img(RequestInterface $request,\League\Flysystem\Filesystem $filesystem){
        $file = $request->file('avatar_url');
        $stream = fopen($file->getRealPath(), 'r+');
//        print_r($file->getClientFilename());
        $user_pach = 'avatar/'.time().$file->getClientFilename();
        $filesystem->writeStream(
            $user_pach,
            $stream
        );
        return [
            "code"=>10000,
            "message"=>"成功",
            "content"=>["surl"=>"https://jingyios.oss-cn-beijing.aliyuncs.com/".$user_pach],
        ];
    }

    public function upload_aiimg(RequestInterface $request,\League\Flysystem\Filesystem $filesystem){
        $file = $request->file('aiimg_url');
//        echo "参数参数".PHP_EOL;
//        print_r($file).PHP_EOL;
        $stream = fopen($file->getRealPath(), 'r+');
//        print_r($file->getClientFilename());
        $user_pach = 'aiimg/'.time().$file->getClientFilename();
        $filesystem->writeStream(
            $user_pach,
            $stream
        );
         $rect_data = [
            "code"=>10000,
            "message"=>"成功",
            "content"=>["surl"=>"https://wodfstml.hainanmlwl.com/".$user_pach],
        ];
//        print_r($rect_data).PHP_EOL;
        return $rect_data;
    }
}
